package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.api.ResultCode;
import com.macro.mall.common.exception.Asserts;
import com.macro.mall.common.utils.Assist;
import com.macro.mall.mapper.UmsServiceDeptLogMapper;
import com.macro.mall.model.UmsServiceDeptLog;
import com.macro.mall.service.UmsServiceDeptLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * UmsServiceDeptLog的服务接口的实现类
 * 
 * @author gaodx
 *
 */
@Slf4j
@Service
public class UmsServiceDeptLogServiceImpl implements UmsServiceDeptLogService {

    private boolean isDebugEnabled;

	@Autowired
	private UmsServiceDeptLogMapper umsServiceDeptLogMapper;
	// TODO 当你看到这个方法时你应该创建一个工具类做通用的方法,定义自己的返回格式化

	@Override
	public List<UmsServiceDeptLog> find(UmsServiceDeptLog value, Integer pageNum, Integer pageSize) {
		//TODO这里可以做通过Assist做添加查询
        PageHelper.startPage(pageNum,pageSize);
        List<UmsServiceDeptLog> result = null;
        Assist assist = new Assist();
        try {
            if(value.getDeptId() != null) {
                assist.andEq("dept_Id",value.getDeptId());
            }
            assist.setOrder(Assist.order("operator_time",false));
            result = umsServiceDeptLogMapper.selectUmsServiceDeptLog(assist);
        } catch (Exception e) {
            log.error("", e);
            Asserts.fail(ResultCode.FAILED);
        }
        if (isDebugEnabled) {
            log.debug("执行获取UmsServiceDeptLog数据集-->结果:", result);
        }
		return result;
	}
	@Override
	public UmsServiceDeptLog findOne(Integer id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过UmsServiceDeptLog的id获得UmsServiceDeptLog对象-->失败:id不能为空");
			}
            Asserts.fail("执行通过UmsServiceDeptLog的id获得UmsServiceDeptLog对象-->失败:id不能为空");
		}
		UmsServiceDeptLog result = null;
        try {
            result = umsServiceDeptLogMapper.selectUmsServiceDeptLogById(id);
        } catch (Exception e) {
        log.error("", e);
            Asserts.fail(ResultCode.FAILED);
        }
		if (isDebugEnabled) {
			log.debug("执行通过UmsServiceDeptLog的id获得UmsServiceDeptLog对象-->结果:", result);
		}
		return result;
	}

	@Override
	public CommonResult saveNotNull(UmsServiceDeptLog value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行将UmsServiceDeptLog中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
                Asserts.fail("失败:对象不能为空");
		}
		int result = 0;
        try {
            result = umsServiceDeptLogMapper.insertNotNullUmsServiceDeptLog(value);
        } catch (Exception e) {
            log.error("", e);
            Asserts.fail(ResultCode.FAILED);
        }
		if (isDebugEnabled) {
			log.debug("执行将UmsServiceDeptLog中属性值不为null的数据保存到数据库-->结果:", result);
		}
            return CommonResult.success(null);
	}
	@Override
	public CommonResult updateNotNullById(UmsServiceDeptLog value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行通过UmsServiceDeptLog的id更新UmsServiceDeptLog中属性不为null的数据-->失败:对象为null");
			}
                Asserts.fail("执行通过UmsServiceDeptLog的id更新UmsServiceDeptLog中属性不为null的数据-->失败:对象为null");
		}
		int result = 0;
        try {
            result = umsServiceDeptLogMapper.updateNotNullUmsServiceDeptLogById(value);
        } catch (Exception e) {
            log.error("", e);
            Asserts.fail(ResultCode.FAILED);
        }
		if (isDebugEnabled) {
			log.debug("执行通过UmsServiceDeptLog的id更新UmsServiceDeptLog中属性不为null的数据-->结果:", result);
		}
        return CommonResult.success(null);
	}

	@Override
	public CommonResult deleteById(Integer id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过UmsServiceDeptLog的id删除UmsServiceDeptLog-->失败:id不能为空");
			}
                Asserts.fail("执行通过UmsServiceDeptLog的id删除UmsServiceDeptLog-->失败:id不能为空");
		}
		int result = 0;
        try {
            result = umsServiceDeptLogMapper.deleteUmsServiceDeptLogById(id);
        } catch (Exception e) {
            log.error("", e);
            Asserts.fail(ResultCode.FAILED);
        }
		if (isDebugEnabled) {
			log.debug("执行通过UmsServiceDeptLog的id删除UmsServiceDeptLog-->结果:", result);
		}
        return CommonResult.success(null);
	}


}